package com.jiazhong.example.project.bookstore.commons.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jiazhong.example.project.bookstore.commons.bean.Power;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PowerMapper extends BaseMapper<Power> {
    @Select("select * from power where id in(select power_id from user_power where user_id=#{userId})")
    List<Power> findPowerByUserId(String userId);


    @Select("select name from power where id in(select power_id from user_power where user_id=#{userId})")
    List<String> findPowerByUserId2(String userId);

    // 删除指定用户的所有权限
    @Delete("delete from user_power where user_id=#{userId}")
    int removeByUserId(String userId);

    // 添加该用户的权限
    @Insert("insert into user_power values(null,#{userId},#{powerId},now())")
    int insertPowerByUserId(@Param("userId") String userId, @Param("powerId") String powerId);

}
